<template>
  <content-wrap>
    <div class="flex justify-between">
      <el-form
        :model="queryParams"
        ref="queryFormRef"
        :inline="true"
        label-width="100px"
        label-position="left"
      >
        <el-form-item label="租户名" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入租户名"
            clearable
            class="!w-260px"
          />
        </el-form-item>
        <el-form-item label="联系人" prop="contactName">
          <el-input
            v-model="queryParams.contactName"
            placeholder="请输入联系人"
            clearable
            class="!w-260px"
          />
        </el-form-item>
        <el-form-item label="联系手机" prop="contactMobile">
          <el-input
            v-model="queryParams.contactMobile"
            placeholder="联系手机"
            clearable
            class="!w-260px"
          />
        </el-form-item>
        <el-form-item>
          <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
          <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
        </el-form-item>
      </el-form>
      <div>
        <el-button type="primary" plain @click="accountOpening">开户申请</el-button>
        <el-button type="primary" plain @click="rechargeApplica">充值申请</el-button>
      </div>
    </div>
    <el-table v-loading="loading" :data="list" border>
      <el-table-column label="租户编号" prop="id" width="90px" />
      <el-table-column label="租户名" align="left" prop="name">
        <template #default="scope">
          <div class="flex items-center justify-left">
            <el-tag class="mr-10px" :type="scope.row.bizType == 2 ? 'danger' : ''" effect="dark">{{
              scope.row.bizType == 1 ? '租户' : '代理'
            }}</el-tag>
            <span>{{ scope.row.name }}</span>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="联系人" prop="contactName" width="100px" />
      <el-table-column label="联系手机" prop="contactMobile" width="130px" />
      <el-table-column label="余额" prop="wallet" width="100px" />
      <el-table-column label="话费成本价" prop="callCostPrice" width="100px" />
      <el-table-column label="话费销售价" prop="callSalePrice" width="100px" />

      <el-table-column label="绑定域名" align="left" prop="website" width="200px" />
      <el-table-column label="租户状态" align="center" prop="status" width="120">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
        :formatter="dateFormatter"
      />
      <el-table-column
        label="过期时间"
        align="center"
        prop="expireTime"
        width="180"
        :formatter="dateFormatter"
      />
    </el-table>
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </content-wrap>
  <Apeningapplication ref="apeningRef" />
  <RechargeApplication ref="rechargeRef" />
</template>

<script setup>
import * as proxyApi from '@/api/home/proxy.ts'
import Apeningapplication from './Apeningapplication.vue'
import RechargeApplication from './rechargeApplication.vue'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'

const list = ref([])
const total = ref(0)
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  contactMobile: null,
  contactName: null,
  name: ''
})

const apeningRef = ref(null)
/**开户申请*/
const accountOpening = () => {
  apeningRef.value.open()
}
const rechargeRef = ref(null)
/**充值申请*/
const rechargeApplica = () => {
  rechargeRef.value.open()
}
/**搜索*/
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}
/**重置*/
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}
/**列表*/
const getList = async () => {
  const data = await proxyApi.subCustomerPage(queryParams)
  list.value = data.list
  total.value = data.total
}
onMounted(() => {
  getList()
})

defineExpose({ getList })
</script>

<style lang="scss" scoped></style>
